/**
 * 日历需要引用以下代码 <div style="background:#99999E;width:250;height:250;border:1px
 * solid black;position:relative;margin:1px auto;"> <canvas id="clock"
 * width="250" height="250" style="border:0px solid #d3d3d3;"></canvas> <canvas
 * id="sec" width="10" height="200"
 * style="position:absolute;top:22px;left:128px;border:0px solid #d3d3d3;"></canvas>
 * <canvas id="min" width="10" height="200"
 * style="position:absolute;top:22px;left:128px;border:0px solid #d3d3d3;"></canvas>
 * <canvas id="hour" width="10" height="200"
 * style="position:absolute;top:22px;left:128px;border:0px solid #d3d3d3;"></canvas>
 * </div>
 * 
 * @type
 */
var Calendar = {
	timerID : null,
	timerRunning : false,
	// 创建一个数组,用于存放每个月的天数
	montharr : function(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
		this[0] = m0;
		this[1] = m1;
		this[2] = m2;
		this[3] = m3;
		this[4] = m4;
		this[5] = m5;
		this[6] = m6;
		this[7] = m7;
		this[8] = m8;
		this[9] = m9;
		this[10] = m10;
		this[11] = m11;
	},
	// 实现月历
	calendar : function() {
		var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
		var today = new Date();
		var thisDay;
		var monthDays = new Calendar.montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
				30, 31);
		year = today.getYear() + 1900;
		thisDay = today.getDate();
		if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
			monthDays[1] = 29;
		nDays = monthDays[today.getMonth()];
		firstDay = today;
		firstDay.setDate(1);
		testMe = firstDay.getDate();
		if (testMe == 2)
			firstDay.setDate(0);
		startDay = firstDay.getDay();
		
		var dayNames = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五",
				"星期六");
		var monthNames = new Array("1月", "2月", "3月", "4月", "5月", "6月", "7月",
				"8月", "9月", "10月", "11月", "12月");
		var now = new Date();
		
		var temp = "<TABLE width='100%' height='100%' BORDER='0' CELLSPACING='0' CELLPADDING='2' BGCOLOR='#BDBEBD'>"
				+"<TR><TD><table width='100%' height='100%' border='1' cellspacing='1' cellpadding='2' bgcolor='#F0F3EC'>"
				+"<TR><th colspan='7' bgcolor='#C8E3FF' style='text-align:center;height: 55px;>"
				+"<FONT STYLE='font-size:9pt;Color:#330099'>" + "公元 "
				+ now.getFullYear() + "年" + monthNames[now.getMonth()] + " "
				+ now.getDate() + "日 " + dayNames[now.getDay()] + Nl.getCalendar()+this.getGG() +"</FONT>"
				+"</TH></TR><TR><TH BGCOLOR='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>日</FONT></TH>"
				+"<th bgcolor='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>一</FONT></TH>"
				+"<TH BGCOLOR='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>二</FONT></TH>"
				+"<TH BGCOLOR='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>三</FONT></TH>"
				+"<TH BGCOLOR='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>四</FONT></TH>"
				+"<TH BGCOLOR='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>五</FONT></TH>"
				+"<TH BGCOLOR='#0080FF' style='text-align:center;'><FONT STYLE='font-size:9pt;Color:White'>六</FONT></TH>"
				+"</TR><TR>";
		column = 0;
		for (i = 0; i < startDay; i++) {
			temp +="<TD><FONT STYLE='font-size:9pt'> </FONT></TD>";
			column++;
		}

		for (i = 1; i <= nDays; i++) {
			if (i == thisDay) {
				temp +="</TD><TD ALIGN='CENTER' BGCOLOR='#FF8040'><FONT STYLE='font-size:9pt;Color:#ffffff'><B>";
			} else {
				temp +="</TD><TD BGCOLOR='#FFFFFF' ALIGN='CENTER'><FONT STYLE='font-size:9pt;font-family:Arial;font-weight:bold;Color:#330066'>";
			}
			temp +=i;
			if (i == thisDay)
				temp +="</FONT></TD>";
			column++;
			if (column == 7) {
				temp +="<TR>";
				column = 0;
			}
		}
		temp +="<TR><TD COLSPAN='7' ALIGN='CENTER' VALIGN='TOP' BGCOLOR='#0080FF'>";
		temp +="<FORM NAME='clock' onSubmit='0'><FONT STYLE='font-size:9pt;Color:#ffffff'>";
		temp +="现在时间:<INPUT TYPE='Text' NAME='face' ALIGN='TOP'></FONT></FORM></TD></TR></TABLE>";
		temp +="</TD></TR></TABLE>";
		document.getElementById("rili").innerHTML = temp;
	},
	stopclock : function() {
		if (this.timerRunning)
			clearTimeout(this.timerID);
		this.timerRunning = false;
	},
	// 显示当前时间
	showtime : function() {
		var now = new Date();
		var hours = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds()
		var timeValue = " " + ((hours > 12) ? hours - 12 : hours)
		timeValue += ((minutes < 10) ? ":0" : ":") + minutes
		timeValue += ((seconds < 10) ? ":0" : ":") + seconds
		timeValue += (hours >= 12) ? " 下午 " : " 上午 "
		document.clock.face.value = timeValue;
		this.timerID = setTimeout(function(){
			Calendar.showtime();
		}, 1000);// 设置超时,使时间动态显示
		this.timerRunning = true;
	},
	startclock : function() {
		this.stopclock();
		this.showtime();
	},
	getGG:function(){
		return '<marquee height=50 direction=left scrolldelay=120 behavior=alternate>'
					+ '<FONT id="nlgg" COLOR="'+ggColor+'" STYLE="font-size:9pt;"><b>'
					+ this.solarTerms
					+ ' '
					+ this.solarFestival
					+ ' '
					+ this.lunarFestival
					+ '</b></FONT></marquee>'	
	},
	init : function() {
		this.calendar();
		this.startclock();
	}
}